<?php
	session_start();
	require 'include/configDB.php';

	// if (!isset($_SESSION['role']) || ($_SESSION['role'] != "Guru") || ($_SESSION['role'] != "Admin")) {
	// 	// redirect ke page login
	// 	header('Location: login.php');
	// }
	
	$guru = mysql_query("SELECT * FROM nilai");
	if (isset($_POST['tahun_ajaran'])) {
		$tahun_ajaran = $_POST['tahun_ajaran'];

	}
	if (isset($_POST['matpel'])) {
		$matpel = $_POST['matpel'];

	}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Laporan Nilai Mata Pelajaran</title>
<link rel="stylesheet" type="text/css" href="style.css" />
<script type="text/javascript" src="clockp.js"></script>
<script type="text/javascript" src="clockh.js"></script> 
<script type="text/javascript" src="jquery.min.js"></script>
<script type="text/javascript" src="ddaccordion.js"></script>
<script type="text/javascript">
ddaccordion.init({
	headerclass: "submenuheader", //Shared CSS class name of headers group
	contentclass: "submenu", //Shared CSS class name of contents group
	revealtype: "click", //Reveal content when user clicks or onmouseover the header? Valid value: "click", "clickgo", or "mouseover"
	mouseoverdelay: 200, //if revealtype="mouseover", set delay in milliseconds before header expands onMouseover
	collapseprev: true, //Collapse previous content (so only one open at any time)? true/false 
	defaultexpanded: [], //index of content(s) open by default [index1, index2, etc] [] denotes no content
	onemustopen: false, //Specify whether at least one header should be open always (so never all headers closed)
	animatedefault: false, //Should contents open by default be animated into view?
	persiststate: true, //persist state of opened contents within browser session?
	toggleclass: ["", ""], //Two CSS classes to be applied to the header when it's collapsed and expanded, respectively ["class1", "class2"]
	togglehtml: ["suffix", "<img src='images/plus.gif' class='statusicon' />", "<img src='images/minus.gif' class='statusicon' />"], //Additional HTML added to the header when it's collapsed and expanded, respectively  ["position", "html1", "html2"] (see docs)
	animatespeed: "fast", //speed of animation: integer in milliseconds (ie: 200), or keywords "fast", "normal", or "slow"
	oninit:function(headers, expandedindices){ //custom code to run when headers have initalized
		//do nothing
	},
	onopenclose:function(header, index, state, isuseractivated){ //custom code to run whenever a header is opened or closed
		//do nothing
	}
})

</script>

<script type="text/javascript" src="jconfirmaction.jquery.js"></script>
<script type="text/javascript">

	$(document).ready(function() {
		function loadMataPelajaran() {
			var kelas_value = $("#kelas").val();
			var jurusan_value = $("#jurusan").val();
			var no_kelas_value = $("#no_kelas").val();
			var id_guru_value = "<?php echo ($_SESSION['role'] == 'Guru') ? $_SESSION['id_pengguna'] : ''; ?>";
			var id_matpel_value = "<?php echo isset($_POST['matpel']) ? $_POST['matpel'] : ''; ?>";
			var form_data = {kelas: kelas_value, jurusan: jurusan_value, no_kelas: no_kelas_value, id_guru: id_guru_value, id_matpel: id_matpel_value};

			$.ajax({
			    url : "include/get_mata_pelajaran.php",
			    type: "POST",
			    data : form_data,
			    success: function(data, textStatus, jqXHR)
			    {
			        //data - response from server
			        $("#matpel").find('option').remove();
			        // split
			        /*var matpel = data.split("-");
			        var i;
			        for (i = 0; i < matpel.length - 1; i++) {
			        	var matpel_split = matpel[i].split("+");
			        	$('#matpel').append('<option value="' + matpel_split[0] + '">' + matpel_split[1] + '</option>');
			        }*/
			        $('#matpel').append(data);
			        //alert(data);
			    },
			    error: function (jqXHR, textStatus, errorThrown)
			    {
			 		//alert(textStatus);
			    }
			});
		}

		$('.ask').jConfirmAction();
		$('#kelas').change(function() {
			loadMataPelajaran();
		});
		$('#jurusan').change(function() {
			loadMataPelajaran();
		});
		$('#no_kelas').change(function() {
			loadMataPelajaran();
		});

		loadMataPelajaran();
	});
	
</script>

<script language="javascript" type="text/javascript" src="niceforms.js"></script>
<link rel="stylesheet" type="text/css" media="all" href="niceforms-default.css" />
<style>
	<?php include 'include_style.php'; ?>
</style>
</head>
<body>
<div id="main_container">

	<?php include 'header.php'; ?>
    
    <div class="main_content">
                
                    
    <div class="center_content">  
    
	
    <div class="left_content">

    	<?php include 'left_content.php'; ?>
    	<?php include 'calendar.php' ; ?>
    
    </div>  
    
    <div class="right_content">
	<h2>Data Nilai Akademik</h2>
	<form action="laporan_data_nilaiMatpel.php" method="post" >  
		<table>
			<tr>
				<td>
					Tahun Ajaran 
				</td>
				<td>
					:
				</td>
				<td>
					<select name = "tahun_ajaran">
						<option value="">---------Pilih----------</option>
						<?php
						$query = mysql_query("SELECT * FROM tahun_ajaran");
						while ($tahun_ajaran_data = mysql_fetch_array($query)) {
						?>
						<option value="<?php echo $tahun_ajaran_data['id'];?>" <?php if (isset($_POST['tahun_ajaran']) && ($_POST['tahun_ajaran'] == $tahun_ajaran_data['id'])) echo "selected";?>>
							<?php echo $tahun_ajaran_data['tahun_ajaran'];?>
						</option>
						<?php } ?>	
					</select>
				</td>
			</tr>
			<tr>
				<td>
					Kelas 
				</td>
				<td>
					:
				</td>
				<td>
					<select name="kelas" id="kelas">
						<option value="">---------Pilih----------</option>
						<option value="10" <?php if (isset($_POST['kelas']) && ($_POST['kelas'] == '10')) echo "selected";?>>10</option>
						<option value="11" <?php if (isset($_POST['kelas']) && ($_POST['kelas'] == '11')) echo "selected";?>>11</option>
						<option value="12" <?php if (isset($_POST['kelas']) && ($_POST['kelas'] == '12')) echo "selected";?>>12</option>	
					</select>
				</td>
				<td>
					Jurusan 
				</td>
				<td>
					:
				</td>
				<td>
					<select name="jurusan" id="jurusan">
						<option value="">---------Pilih----------</option>
						<?php
						$query = mysql_query("SELECT * FROM jurusan");
						while ($data = mysql_fetch_assoc($query)) {
						?>
						<option value="<?php echo $data['id'];?>" <?php if (isset($_POST['jurusan']) && ($_POST['jurusan'] == $data['id'])) echo "selected";?>><?php echo $data['nama'];?>
						</option>
						<?php } ?>
					</select>
				</td>
				<td>
					<select name="no_kelas" id="no_kelas">
						<option value="NULL">---------Pilih----------</option>
						<option value="1" <?php if (isset($_POST['no_kelas']) && ($_POST['no_kelas'] == '1')) echo "selected";?>>1</option>
						<option value="2" <?php if (isset($_POST['no_kelas']) && ($_POST['no_kelas'] == '2')) echo "selected";?>>2</option>
						<option value="3"  <?php if (isset($_POST['no_kelas']) && ($_POST['no_kelas'] == '3')) echo "selected";?>>3</option>	
					    <option value="4"  <?php if (isset($_POST['no_kelas']) && ($_POST['no_kelas'] == '4')) echo "selected";?>>4</option>
					    <option value="5"  <?php if (isset($_POST['no_kelas']) && ($_POST['no_kelas'] == '5')) echo "selected";?>>5</option>
					</select>
				</td>
			</tr>
			<tr>
				<td>
					Semester 
				</td>
				<td>
					:
				</td>
				<td>
					<select name="semester">
						<option value="">---------Pilih----------</option>
						<option value="Genap" <?php if (isset($_POST['semester']) && ($_POST['semester'] == "Genap")) echo "selected";?>>Genap</option>
						<option value="Ganjil" <?php if (isset($_POST['semester']) && ($_POST['semester'] == "Ganjil")) echo "selected";?>>Ganjil</option>
					</select>
				</td>
			</tr>
			<tr>	
				<td>
					Nama Mata Pelajaran 
				</td>
				<td>
					:
				</td>
				<td>
					<select name="matpel" id="matpel">
						<option value="">---------Pilih----------</option>
					</select>
				</td>
			</tr>
			<tr>	
				<td><input type="submit" name="submit" class="menuitem_red"value="Lihat"/></td>
			</tr>
		</table>
		</form>
		<form>
		</br>
		</br>
		<table id="rounded-corner" summary="2007 Major IT Companies' Profit">
			<thead>
				<tr>
					<th scope="col" class="rounded">No</th>
					<th scope="col" class="rounded">Tipe Nilai</th>
					<th scope="col" class="rounded">Keterangan</th>
					<th scope="col" class="rounded">Edit</th>
					<th scope="col" class="rounded-q4">Delete</th>
				</tr>
			</thead>
				<?php
					if(isset($_POST['kelas']) && isset($_POST['jurusan']) && isset($_POST['tahun_ajaran']) && isset($_POST['semester']) && isset($_POST['no_kelas']) && isset($_POST['matpel']))
					{
						$matpel = $_POST['matpel'];
						// echo "$matpel";
						$kelas = $_POST['kelas'];
						//echo "kelas $kelas ";
						$id_jurusan = $_POST['jurusan'];
						//echo "jurusan $id_jurusan ";
						$no_kelas = $_POST['no_kelas'];
						//echo "tingkat $no_kelas ";
						$id_tahun_ajaran = $_POST['tahun_ajaran'];
						// echo "$id_tahun_ajaran";
						$query_kelas = mysql_query("SELECT * FROM kelas WHERE tingkat='$kelas' AND id_jurusan='$id_jurusan' AND nomor='$no_kelas' AND id_tahun_ajaran = '$id_tahun_ajaran'");
						$kelas_data = mysql_fetch_assoc($query_kelas);
						$semester = $_POST['semester'];
						// echo "$semester";
						$id = $kelas_data['id'];
						// echo "$id";
						$query_nilai = mysql_query("SELECT DISTINCT tipe_nilai, keterangan FROM nilai WHERE id_kelas='$id' AND semester ='$semester' AND id_matpel='$matpel' ");
					}

				?>

			<tbody>
				<?php
					if(isset($_POST['kelas']) && isset($_POST['jurusan']) && isset($_POST['tahun_ajaran']) && isset($_POST['semester']) && isset($_POST['no_kelas']))
					{
						$i = 1;
						// $counter_ulangan = 0;
						// $counter_tugas = 0;
						// $counter_ujian = 0;
						while($nilai_data = mysql_fetch_assoc($query_nilai))
						{
						// 	if ($nilai_data['tipe_nilai'] == "Ulangan") {
						// 		$counter_ulangan++;
						// 		$counter = $counter_ulangan;
						// 	}else if ($nilai_data['tipe_nilai'] == "Tugas") {
						// 		$counter_tugas++;
						// 		$counter = $counter_tugas;
						// 	}else{
						// 		$counter_ujian++;
						// 		$counter = $counter_ujian;
						// 	}	

						 echo 
						 '
						 	<tr>
						 		<td>'.$i.'</td>
								<td>'.$nilai_data['tipe_nilai'].'</td>
								<td>'.$nilai_data['tipe_nilai'].' '.$nilai_data['keterangan'].'</td>
								<td><a href="edit_nilai_matpel.php?kelas='.$_POST['kelas'].'&jurusan='.$_POST['jurusan'].'&tahun_ajaran='.$_POST['tahun_ajaran'].'&semester='.$_POST['semester'].'&no_kelas='.$_POST['no_kelas'].'&matpel='.$_POST['matpel'].'&tipe_nilai='.$nilai_data['tipe_nilai'].'&keterangan='.$nilai_data['keterangan'].'"><img src="images/user_edit.png" alt="" title="" border="0" /></a></td>
								<td><a href="include/delete_nilai_matpel.php?tipe_nilai='.$nilai_data['tipe_nilai'].'&keterangan='.$nilai_data['keterangan'].'" class="ask"><img src="images/trash.png" alt="" title="" border="0" /></a></td>
							</tr>
						 
						 ';
						 $i++;
					}
				}	
				?>
			</tbody>
		</table>
		<a class="menuitem_red" href="input_nilai_matpel.php?kelas=<?php echo $_POST['kelas'];?>&jurusan=<?php echo $_POST['jurusan'];?>&tahun_ajaran=<?php echo $_POST['tahun_ajaran'];?>&semester=<?php echo $_POST['semester'];?>&no_kelas=<?php echo $_POST['no_kelas'];?>&matpel=<?php echo $_POST['matpel'];?>&tipe_nilai=<?php echo $nilai_data['tipe_nilai'];?>">Tambah</a>
    </div><!-- end of right content-->
            
                    
  </div>   <!--end of center content -->               
                    
                    
    
    
    <div class="clear"></div>
    </div> <!--end of main content-->
	
    
    <div class="footer">
        	<?php include 'footer.php'; ?>

    	
    </div>

</div>	
</form>	
</body>
</html>